import Vue from 'vue'
import axios from 'axios'
import router from '../router'
Vue.use(require('vue-wechat-title'))
import { Notify, AppFullscreen } from 'quasar'
import QS from 'qs'
Vue.prototype.$Notify = Notify

Vue.config.productionTip = false

axios.defaults.baseURL = process.env.API
axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8'
axios.defaults.withCredentials = true
axios.interceptors.request.use(config => {
  if (config.method === 'post') {
    config.data = QS.stringify(config.data)// 防止post请求参数无法传到后台
  }
  return config
}, error => {
  return Promise.reject(error)
})

Vue.prototype.$axios = axios
// 根据路由设置标题
router.afterEach((to) => {
  /* 路由发生改变修改页面的title */
  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = 'novel.ineedthis'
  }
})
// 请求全屏模式：
AppFullscreen.request()
  .then(() => { // v1.5.0+
    // success!
  })
  // eslint-disable-next-line handle-callback-err
  .catch(err => { // v1.5.0+
    // oh, no!!!
  })
